package org.elanfox.intellicommunity.biz.service.core.msg.impl;

import org.elanfox.intellicommunity.biz.dto.msg.AlarmWorkOrderSaveDTO;
import org.elanfox.intellicommunity.biz.entity.msg.AlarmWorkOrderPO;
import org.elanfox.intellicommunity.biz.repository.msg.AlarmWorkOrderRepository;
import org.elanfox.intellicommunity.biz.service.core.msg.AlarmWorkOrderService;
import org.elanfox.intellicommunity.common.utils.RandomUtils;
import org.elanfox.intellicommunity.data.base.base.AbstractSearchableCrudService;
import org.elanfox.intellicommunity.data.base.base.SpecificationAndSort;
import org.elanfox.intellicommunity.data.base.dto.BaseSaveDTO;
import org.elanfox.intellicommunity.data.base.dto.BaseSearchDTO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

/**
 * @author allan
 * @version 1.0.0
 * @date 2019/12/27
 */
@Service
public class AlarmWorkOrderServiceImpl extends AbstractSearchableCrudService<AlarmWorkOrderPO, String> implements AlarmWorkOrderService {
    private AlarmWorkOrderRepository alarmWorkOrderRepository;

    @Autowired
    protected AlarmWorkOrderServiceImpl(AlarmWorkOrderRepository repository) {
        super(repository);
        this.alarmWorkOrderRepository = repository;
    }

    @Override
    protected SpecificationAndSort<AlarmWorkOrderPO> specificationAndSort(BaseSearchDTO searchDTO) {
        return null;
    }

    @Override
    @Transactional
    public AlarmWorkOrderPO save(BaseSaveDTO saveDTO) {
        AlarmWorkOrderSaveDTO orderSaveDTO = (AlarmWorkOrderSaveDTO) saveDTO;

        AlarmWorkOrderPO alarmWorkOrderPO = new AlarmWorkOrderPO();
        alarmWorkOrderPO.setId(RandomUtils.randomFlowNo());
        alarmWorkOrderPO.setAlarmMsgGroupPO(orderSaveDTO.getAlarmMsgGroupPO());
        alarmWorkOrderPO.setHandleAddr(orderSaveDTO.getHandleAddr());
        alarmWorkOrderPO.setReason(orderSaveDTO.getReason());
        alarmWorkOrderPO.setPoliceName(orderSaveDTO.getPoliceName());
        alarmWorkOrderPO.setPoliceMobile(orderSaveDTO.getPoliceMobile());
        alarmWorkOrderPO.setReason(orderSaveDTO.getReason());
        alarmWorkOrderPO.setRemark(orderSaveDTO.getRemark());

        return repository.save(alarmWorkOrderPO);
    }

    @Override
    public AlarmWorkOrderPO findByGroup(Long groupId) {
        return alarmWorkOrderRepository.findByAlarmMsgGroupPO_GroupId(groupId);
    }
}
